package org.taobao.ibatiside.ui.util;

import org.apache.commons.lang.StringUtils;

public class DefaultNamingConversion implements INamingConversion {

	@Override
	public String getDataObjectName(String tableName) {
		StringBuffer tb_buffer = new StringBuffer(MiscHelper.sqlId2JavaId(tableName));
		tb_buffer.setCharAt(0, Character.toUpperCase(tb_buffer.charAt(0)));
		tb_buffer.append("DO");
		return tb_buffer.toString();
	}
	private String getCommonStmtName(String[] tables, String[] conditions){
		if (tables.length == 0) return "foo";
		StringBuffer sb = new StringBuffer();
		sb.append(StringUtils.capitalize(MiscHelper.sqlId2JavaId(tables[0])));
		if (tables.length > 1){
			sb.append("More");
		}
		sb.append("By");
		if (conditions.length > 0){
			sb.append(StringUtils.capitalize(MiscHelper.sqlId2JavaId(conditions[0])));
		}
		if (conditions.length > 1){
			sb.append("_");
			sb.append(StringUtils.capitalize(MiscHelper.sqlId2JavaId(conditions[1])));
		}
		if (conditions.length > 2){
			sb.append("_");
			sb.append("More");
		}
		return sb.toString();
	}
	@Override
	public String getUpdateStmtName(String[] tables, String[] conditions) {
		return "update"+StringUtils.capitalize(getCommonStmtName(tables, conditions));
	}

	@Override
	public String getInsertStmtName(String[] tables, String[] conditions) {
		return "insert"+StringUtils.capitalize(getCommonStmtName(tables, conditions));
	}

	@Override
	public String getSelectStmtName(String[] tables, String[] conditions) {
		return "select"+StringUtils.capitalize(getCommonStmtName(tables, conditions));
	}

	@Override
	public String getDeleteStmtName(String[] tables, String[] conditions) {
		return "delete"+StringUtils.capitalize(getCommonStmtName(tables, conditions));
	}

	@Override
	public String getDAOInterfaceName(String tableName) {
		StringBuffer tb_buffer = new StringBuffer(MiscHelper.sqlId2JavaId(tableName));
		tb_buffer.setCharAt(0, Character.toUpperCase(tb_buffer.charAt(0)));
		tb_buffer.append("DAO");
		return tb_buffer.toString();
	}

	@Override
	public String getDAOImplName(String tableName) {
		StringBuffer tb_buffer = new StringBuffer(MiscHelper.sqlId2JavaId(tableName));
		tb_buffer.setCharAt(0, Character.toUpperCase(tb_buffer.charAt(0)));
		tb_buffer.append("DAO").append("Impl");
		return tb_buffer.toString();
	}

}
